package ship.service;
import java.util.List;
import ship.dao.shipDao;
import ship.entity.usertable;
import ship.entity.shipinformation;
import ship.entity.stafftable;
import ship.entity.orderifm;

//业务逻辑层：调用DAO层功能
public class shipservice {
	shipDao shipDao = new shipDao();

//根据查询sid and sname 用户登录
	public boolean Loginbyusertablesidandsname(int sid,String sname) {
	        usertable user = shipDao.queryusertablebysid(sid);
	        if(user!=null&&sname.equals(user.getSname())){
	        return true;
	        }
	        return false;
}
//根据查询sno and snm 管理员登录
		public boolean Loginbystafftablesnoandsnm(int sno,String snm) {
		        stafftable staff = shipDao.querystafftablebysno(sno);
		        if(staff!=null&&snm.equals(staff.getSnm())){
		        return true;
		        }
		        return false;
	}
//根据sno条件查询该员工
	public stafftable querystafftablebysnoelse(int sno) {
		if(shipDao.isExistbysno(sno)){
			return shipDao.querystafftablebysno(sno);
	}
		    return null;
}
//根据sno查询该该员工
		public stafftable querystafftablebysno(int sno) {
			return shipDao.querystafftablebysno(sno);
}
//根据snumber查询订单(修改)
		public orderifm queryorderifmbysnumber(int snumber) {
			return shipDao.queryorderifmbysnumber(snumber);
}
//根据snumber查询(条件)订单
		public orderifm queryorderifmbysnumberelse(int snumber) {
			if(shipDao.isExistbysnumber(snumber)){
			return shipDao.queryorderifmbysnumber(snumber);
		}
			return null;
		}
//根据sname查询用户(登+个人)
		public usertable queryusertablebysname(String sname) {
			return shipDao.queryusertablebysname(sname);
	}
//根据sname查询该订单（个人）
		public List<orderifm> queryorderifmbysname(String sname) {
					return shipDao.queryorderifmbysname(sname);
}
//根据sid查询用户
	public usertable queryusertablebysid(int sid) {
		return shipDao.queryusertablebysid(sid);
}
//根据sid条件查询该用户
		public usertable queryusertablebysidelse(int sid) {
		if(shipDao.isExistbysid(sid)){
			return shipDao.queryusertablebysid(sid);
	}
		    return null;
	}
//根据sn查询该船只信息
	public shipinformation queryshipinformationbysn(int sn) {
		return shipDao.queryshipinformationbysn(sn);
}
//根据sn查询(条件)该船只信息
		public shipinformation queryshipinformationbysnelse(int sn) {
			if(shipDao.isExistbysn(sn)){
				return shipDao.queryshipinformationbysn(sn);
		}
			    return null;
	}
//查询全部员工(0 8)
	public List<stafftable> queryallstafftable() {
		return shipDao.queryallstaffs();
}
//查询全部员工(8 8)
	public List<stafftable> queryallstafftabletwo() {
		return shipDao.queryallstaffstwo();
}
//查询全部员工(16 8)
	public List<stafftable> queryallstafftablethree() {
		return shipDao.queryallstaffsthree();
	}
//查询全部用户(0 8)
	public List<usertable> queryallusertable() {
		return shipDao.queryallusers();
}
//查询全部用户(8 8)
	public List<usertable> queryallusertabletwo() {
		return shipDao.queryalluserstwo();
}
//查询全部用户(16 8)
		public List<usertable> queryallusertablethree() {
			return shipDao.queryallusersthree();
}
//查询全部用户(24 8)
		public List<usertable> queryallusertablefour() {
			return shipDao.queryallusersfour();
		}
//查询全部订单(0 8)
		public List<orderifm> queryallorderifms() {
			return shipDao.queryallorderifms();
}
//查询全部订单(8 8)
		public List<orderifm> queryallorderifmstwo() {
			return shipDao.queryallorderifmstwo();
}
//查询船只信息(0 8)
	    public List<shipinformation> queryshipinformation() {
		    return shipDao.queryshipinformation();
}
//查询船只信息(8 8)
	    public List<shipinformation> queryshipinformationtwo() {
		    return shipDao.queryshipinformationtwo();
}
//根据sno修改员工信息
	public boolean updatestafftable(int sno, stafftable staff){
		   if(shipDao.isExistbysno(sno)){
			   return shipDao.updatestafftable(sno, staff);
		   }
		       return false;
}
//根据sid修改用户信息
    public boolean updateusertable(int sid, usertable user){
	       if(shipDao.isExistbysid(sid)){
		       return shipDao.updateusertable(sid, user);
	   }
	           return false;
}
//根据snumber修改订单信息
    public boolean updateorderifm(int snumber, orderifm ifm){
	       if(shipDao.isExistbysnumber(snumber)){
		       return shipDao.updateorderifm(snumber, ifm);
	   }
	           return false;
}
//根据sn修改船只信息
    public boolean updateshipinformation(int sn, shipinformation information){
	       if(shipDao.isExistbysn(sn)){
		       return shipDao.updateshipinformation(sn, information);
	   }
	           return false;
}
//根据sno删除员工信息
    public boolean deletestafftablebysid(int sno) {
	   if(shipDao.isExistbysno(sno)) {	
		  shipDao.deletestafftablebysid(sno);
		  return true;
	   }
	      return false;
}
//根据sid删除用户信息
    public boolean deleteusertablebysid(int sid) {
	   if(shipDao.isExistbysid(sid)) {	
		  shipDao.deleteusertablebysid(sid);
		  return true;
	   }
	      return false;
}
//根据snumber删除订单信息
    public boolean deleteorderifmbysnumber(int snumber) {
	   if(shipDao.isExistbysnumber(snumber)) {	
		  shipDao.deleteorderifmbysnumber(snumber);
		  return true;
	   }
	      return false;
}
//根据sn下架船只信息
    public boolean deleteshipinformationbysn(int sn) {
	   if(shipDao.isExistbysn(sn)) {	
		  shipDao.deleteshipinformationbysn(sn);
		  return true;
	   }
	      return false;
}
//管理员（员工）注册
    public boolean registstafftable(stafftable staff) {  
	   if(!shipDao.isExistbysno(staff.getSno())&&!shipDao.isExistbysname(staff.getSnm())) {//不存在即增加
		   shipDao.addstafftable(staff);  
		   return true;   
	   }else {
		   return false;
	   } 
}
 //添加员工
    public boolean addstafftable(stafftable staff) {  
	   if(!shipDao.isExistbysno(staff.getSno())) {//不存在即增加
		   shipDao.addstafftable(staff);  
		   return true;   
	   }else {
		   return false;
	   } 
}
//用户注册
    public boolean registusertable(usertable user) {  
	   if(!shipDao.isExistbysid(user.getSid())&&!shipDao.isExistbysname(user.getSname())) {
		   shipDao.addusertable(user);  
		   return true;   
	   }else {
		   return false;  
	   }  
 }
//添加用户
    public boolean addusertable(usertable user) {  
	   if(!shipDao.isExistbysid(user.getSid())) {
		   shipDao.addusertable(user);  
		   return true;   
	   }else {
		   return false;  
	   }  
 }
//添加订单
    public boolean addorderifm(orderifm ifm) {  
	   if(!shipDao.isExistbysnumber(ifm.getSnumber())) {
		   shipDao.addorderifm(ifm);  
		   return true;   
	   }else {
		   return false;  
	   }  
 }
//上架船只信息
    public boolean addshipinformation(shipinformation information) {  
	   if(!shipDao.isExistbysn(information.getSn())) {
		   shipDao.addshipinformation(information);  
		   return true;   
	   }else {
		   return false;  
	   }  
   }
}